package com.mindata.blockchain.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by Ming on 2018/8/7.
 */
@RestController
@RequestMapping("test")
public class DemoController {

//    @Autowired
//    private BlockService blockService;
//
//    @Autowired
//    private InstructionService instructionService;

//    @Autowired
//    A a;
//
//    @Autowired
//    Extends anExtends;

//    @GetMapping("a")
//    public Object test(){
//        return a.print();
//    }
//
//    @GetMapping("b")
//    public Object testb(){
//        return a.printB();
//    }
//
//    @GetMapping("c")
//    public Object c(){
//        return anExtends.getEntityClass();
//    }

//    @GetMapping("rlp")
//    public Object testRLP1(){
//        String key="key";
//        String value="value";
//        byte[] key1= RLP.encodeString(key);
//        byte[] value1= RLP.encodeString(value);
//        RLPList key2=RLP.decode2(key1);
//        RLPList value2=RLP.decode2(value1);
//        byte[] key3=key2.get(0).getRLPData();
//        byte[] value3=value2.get(0).getRLPData();
//        List list=new ArrayList();
//        list.add(key.getBytes());
//        list.add(value.getBytes());
//        list.add(key1);
//        list.add(value1);
//        list.add(key2);
//        list.add(value2);
//        list.add(new String(key3));
//        list.add(new String(value3));
//        return list;
//    }

    @GetMapping("rlpo")
    public Object testRLPObject(){
        return null;
    }

    @GetMapping("100th")
    public Object _100thTest() throws IOException {
        for(int i=0;i<100;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String url="http://localhost:8080/block";
                    URL url1= null;
                    try {
                        url1 = new URL(url);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                    URLConnection connection = null;
                    try {
                        connection = url1.openConnection();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    // 设置通用的请求属性
                    connection.setRequestProperty("accept", "*/*");
                    connection.setRequestProperty("connection", "Keep-Alive");
                    connection.setRequestProperty("user-agent",
                            "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                    // 建立实际的连接
                    try {
                        connection.connect();
                        connection.getInputStream();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        return null;
    }


}
